Skip to content

feat: Add BeforeSendFeedback callback to inspect, modify, or drop user feedback before it's sent#5361

Merged
jamescrosswell merged 3 commits into
getsentry:mainfrom
vladbrincoveanu:feat/4092-before-send-feedback-y
Jul 10, 2026
Merged

feat: Add BeforeSendFeedback callback to inspect, modify, or drop user feedback before it's sent#5361
jamescrosswell merged 3 commits into
getsentry:mainfrom
vladbrincoveanu:feat/4092-before-send-feedback-y

Conversation

@vladbrincoveanu

@vladbrincoveanu vladbrincoveanu commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Refers to #4092

Summary

Adds a BeforeSendFeedback callback to SentryOptions, mirroring the existing BeforeSend pattern but scoped to user feedback events. It lets applications inspect, modify, or drop user feedback before it is sent to Sentry.

Changes

  • Two SetBeforeSendFeedback overloads on SentryOptions (with and without SentryHint), consistent with SetBeforeSend / SetBeforeSendTransaction.
  • SentryEventHelper.DoBeforeSendFeedback, invoked in SentryClient.CaptureFeedback after event processors run.
  • New CaptureFeedbackResult.DroppedByBeforeSendFeedback result value
  • Dropped feedback is recorded via ClientReportRecorder under DiscardReason.BeforeSend / DataCategory.Feedback. Originally, was specified the use of DataCategory USER_REPORT_V2.
    [SDK docs] add new UF data model and implementation details under telemetry dev docs sentry#88232 (comment)

Behavior notes for reviewers

Assumption: Feedback is a common place to scrub PII, so a callback that cannot complete should not leak partially-scrubbed or unintended feedback.
Implementation: Both the null-return and throw paths record a client-report discard. This is documented on the public API and covered by tests.

Tests

SentryClientTests covers: callback invocation + mutation passthrough, hint received from caller, null and throw drops feedback.

Unrelated changes

Added a small unit test for CaptureFeedbackResult.UnknownError.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.19%. Comparing base (4b51c11) to head (7bbbb1c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5361      +/-   ##
==========================================
+ Coverage   74.14%   74.19%   +0.04%     
==========================================
  Files         509      509              
  Lines       18386    18409      +23     
  Branches     3600     3603       +3     
==========================================
+ Hits        13633    13658      +25     
+ Misses       3880     3879       -1     
+ Partials      873      872       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

vladbrincoveanu and others added 3 commits July 9, 2026 12:40
…r feedback before it's sent

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…semantics

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vladbrincoveanu
vladbrincoveanu force-pushed the feat/4092-before-send-feedback-y branch from 1f51fe2 to 7bbbb1c Compare July 9, 2026 10:40
@vladbrincoveanu
vladbrincoveanu marked this pull request as ready for review July 9, 2026 12:10
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Jul 9, 2026

@jamescrosswell jamescrosswell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @vladbrincoveanu ❤️

This looks all good to me. Nothing blocking from my side - I did have one question for you that might help guide the direction of these APIs in the future though.

/// Return null or throw to drop the feedback.
/// </summary>
/// <param name="beforeSendFeedback">The callback</param>
public void SetBeforeSendFeedback(Func<SentryEvent, SentryEvent?> beforeSendFeedback)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a question than a comment, but I'm not sure if we need this overload. Originally we added an overload on the BeforeSend event when we wanted to introduce a variant that accepted a SentryHint parameter without that being a breaking change... we never made a conscious decision that we wanted two overloads of the callback though.

If we only had a single version of the callback that accepted both a SentryEvent and a SentryHint argument, users could easily ignore the second argument.

On the other hand, if we do that now for this callback, SetBeforeSendFeedback is then the odd one out (inconsistent)... so probably not something we want to do in this PR but something we could consider for all of the BeforeSend* callbacks as a breaking change in the next major:

  • Do we want to simplify the BeforeSend* callbacks so that these are not overloaded?

@Flash0ver @vladbrincoveanu what are your thoughts?

@vladbrincoveanu vladbrincoveanu Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These overloads are just adapters. They just use the SentryHint version and their docs hide half the feature.
I agree, we can batch mark them as [Obsolete] for a next minor and remove them in the future major, so users gets some warnings first. This could be another good starter ticket, for cleanups.

3 concerns:

  • the overload without SentryHint is the one used in docs, we need to updated the entries too.
  • by marking them as obsolete first in a minor vers, the consumers either get a warning or their build can actually break if they have TreatWarningsAsErrors set up. Is this acceptable?
  • SetBeforeSendLog and SetBeforeSendMetric do not have 2 overloads and we need to decide if it makes sense to add a SentryHint for logging and metrics.

1 suggestion:

  • another possible doc update: new data for Before callbacks will go into SentryHint, not into a new delegate parameter, so we enforce it. Ofc, if we ever need to add a cancellationtoken or async, we will have a new overload.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can batch mark them as [Obsolete] for a next minor and remove them in the future major

Probably more effort that it's worth... The overloads don't add too much noise.

SetBeforeSendLog and SetBeforeSendMetric do not have 2 overloads and we need to decide if it makes sense to add a SentryHint for logging and metrics.

The main reason for the Hint parameter was to make it possible to pass in attachments... which I don't think make sense for metrics/logs (neither support attachments).

}

[Fact]
public void CaptureFeedback_EnqueueFails_ReturnsUnknownError()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unrelated to this PR but harmless...

@jamescrosswell
jamescrosswell merged commit 0710ded into getsentry:main Jul 10, 2026
45 checks passed
@Flash0ver

Copy link
Copy Markdown
Contributor

Refers to #4092

"Refers" is not a verb that links a PR to an issue.

GitHub links PRs to an issue by using any of these keywords:

close
closes
closed
fix
fixes
fixed
resolve
resolves
resolved

See https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue

@jamescrosswell jamescrosswell linked an issue Jul 10, 2026 that may be closed by this pull request
This was referenced Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add BeforeSendFeedback callback to SentryOptions

3 participants